package com.gewu.bookeeping.View.adapter;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gewu.bookeeping.MyDb.bean.ALIBeanIn;
import com.gewu.bookeeping.MyDb.bean.ALiBeanOut;
import com.gewu.bookeeping.MyDb.bean.MesBeanIn;
import com.gewu.bookeeping.MyDb.bean.WeChtBeanIn;
import com.gewu.bookeeping.MyDb.bean.WeChtBeanOut;
import com.gewu.bookeeping.OnClick.goBack;
import com.gewu.bookeeping.R;
import com.gewu.bookeeping.View.activity.ItemActivity;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class twoItemAdapter extends BaseExpandableListAdapter {

    List<List<MesBeanIn>> listList;
    List<String> time;

    public twoItemAdapter(List<List<MesBeanIn>> listList, List<String> time) {
        this.time = time;
        this.listList = listList;
    }

    @Override
    public int getGroupCount() {
        return time.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return listList.get(groupPosition).size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return time.get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return listList.get(groupPosition).get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition) {
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return groupPosition + childPosition;
    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.one_item_layout, parent, false);
        TextView textView = inflate.findViewById(R.id.etText);
        textView.setText(time.get(groupPosition));
        return inflate;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, final ViewGroup parent) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.one_item_content, parent, false);
        TextView name = inflate.findViewById(R.id.name);
        TextView time = inflate.findViewById(R.id.time);
        TextView type = inflate.findViewById(R.id.type);
        LinearLayout tab = inflate.findViewById(R.id.tab);
        name.setText(listList.get(groupPosition).get(childPosition).getText());
        time.setText(listList.get(groupPosition).get(childPosition).getTime());
        type.setText(listList.get(groupPosition).get(childPosition).getType());
        tab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(parent.getContext(), ItemActivity.class);
                Bundle bundle = new Bundle();
                bundle.putInt("values", 1);
                bundle.putInt("type", 1);
                intent.putExtra("date", bundle);
                parent.getContext().startActivity(intent);
            }
        });
        return inflate;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        return true;
    }
}
